#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#define BUFSIZE 1024

int main(int argc, char * argv[])
{
	FILE * fp_src, * fp_dst;
	char buf[BUFSIZE];
	int ret;
	//参数检验
	if(argc < 3)
	{
		fprintf(stderr, "Usage:%s <src file name> <dst file name>\n", argv[0]);
		exit(1);
	}
	//打开文件
	fp_src = fopen(argv[1], "r");
	if(fp_src == NULL)
	{
		perror("fopen failed");
		exit(1);
	}
	fp_dst = fopen(argv[2], "w");
	if(fp_dst == NULL)
	{
		perror("fopen failed");
		exit(1);
	}
	//当ret不为零,写入ret个字节,记得单字节使用,0为文件尾
	while((ret = fread(buf, 1, BUFSIZE, fp_src)))
	{
		fwrite(buf, 1, ret, fp_dst);
	}
	//关闭文件
	fclose(fp_dst);
	fclose(fp_src);

	exit(0);
}
